<!-- Copyright 2010 John L. Reilly

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.  -->

<%@ page import="java.util.List"%>
<%@ page import="com.riq.entity.Department"%>
<%@ page import="com.riq.entity.Location"%>
<%@ page import="com.riq.entity.Status"%>
<%@ page import="java.util.logging.Logger"%>
<%@ page import="java.io.IOException"%>
<%@ page import="javax.servlet.*"%>

<%
Location l = (Location) request.getAttribute("location"); 
Department d = (Department) request.getAttribute("dept");
List<Status> allStatuses = (List<Status>) request.getAttribute("allStatuses");
List<Long> selectedStatuses = (List<Long>) request.getAttribute("selectedStatuses");
Long timeStamp = System.currentTimeMillis();

System.out.println("selectedStatuses qty: " + selectedStatuses.size());
System.out.println("allStatuses qty: " + allStatuses.size());
System.out.println("allStatuses name: " + allStatuses.get(0).getshortName());
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>FirstResponder</title>

<!--META-->

<meta http-equiv="content-type"  content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width" />

<!--STYLESHEET-->

<link rel="stylesheet" type="text/css" href="stylesheets/static.css" />

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

var deptLayer =  null;
var map;
var marker;

function initialize() {
  var myLatlng = 
    new google.maps.LatLng(<%=l.getlastLat()%>,<%=l.getlastLng()%>);
  var myOptions = {
    zoom: 18,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.HYBRID
  }

  var timestamp = new Date().getTime();
  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

  
  marker = new google.maps.Marker({
      position: myLatlng, 
      map: map,
      draggable: true
  });
  
  google.maps.event.addListener(marker, 'position_changed', showPosition);
  showPosition();
}


function showPosition() {
  document.getElementById("latitude").innerHTML  = marker.getPosition().lat();
  document.getElementById("longitude").innerHTML = marker.getPosition().lng(); 
  document.getElementById("lat").value = marker.getPosition().lat();
  document.getElementById("lng").value = marker.getPosition().lng(); 
}


function show_hide(show, hide)
{
document.getElementById(show).style.display="block";
document.getElementById(hide).style.display="none";
}

</script>

</head>

<body onload="initialize()">

<!--FIXED HEADERS-->
<div class="headwrap">
<div class="hBlack">
<div class="headerLeftTop">FirstResponder</div>
<div class="headerRightTop">ver 0.9</div>
<div class="headerLeftBottom">Location: Edit</div>
<div class="headerRightBottom">12:34 PM</div>
</div>
<div class="hGray">
  <a class="buttonGrayHdr" href="mainMenu.html">Main</a>
  <a class="buttonGrayHdr" href="commandMenu.html">Command</a>
  <a class="buttonGrayHdr gSelected" href="department?action=display">Admin</a>
</div>
<div class="headerMist"></div>
</div>

<div class="outwrap">
<div class="headerPlug"></div>

<!--BUTTONS-->

<div id="centeredButtons"><ul><li>
<a class="button blue narrow tall first last"
   href="department?action=display">
   Cancel</a></li><li>
<a class="button green narrow tall first last"
   href="#" onclick="javascript:document.forms[0].submit();return false;">
   Save</a></li></ul></div>

<!--FORM-->

<form method="post" action="location?action=set">

<input type=hidden name="deptId" value="<%=l.getdeptId().toString()%>" />
<input type=hidden name="locationId" value="<%=l.getid().toString()%>" />
<input type="hidden" id="lat" name="lastLat"></input>
<input type="hidden" id="lng" name="lastLng"></input>

<div class="row title">Short Name (Required):</div>
<div><input class="inputfield" type="input" name="shortName" value="<%=l.getshortName()%>" /></div>    
<div class="row title">Long Name:</div>
<div><input class="inputfield"  type="input" name="longName" value="<%=l.getlongName()%>" /></div>
<div class="row title">Location Type:</div>
<div><input class="inputfield" type="input" name="type" value="<%=l.gettype()%>" /></div>   
<div class="row title">Sequence Number (Required):</div>
<div><input class="inputfield" type="input" name="sequence" value="<%=l.getsequence()%>" /></div>   

<div class="row title">Position:</div>
<div class="row">
<% if ("static".equalsIgnoreCase(l.getposition())) { %>
 <input type="radio" name="position" value="static" class="radioButton"
        onClick="show_hide('static', 'dynamic')" checked />Static</input>
<% } else { %>
 <input type="radio" name="position" value="static" class="radioButton"
        onClick="show_hide('static', 'dynamic')"  />Static</input>
<% } %>

<% if ("dynamic".equalsIgnoreCase(l.getposition())) { %>
 <input type="radio" name="position" value="dynamic" class="radioButton"
        onClick="show_hide('dynamic', 'static')" checked />Dynamic</input>
<% } else { %>
 <input type="radio" name="position" value="dynamic" class="radioButton"
        onClick="show_hide('dynamic', 'static')"  />Dynamic</input>
<% } %>
</div>

<% if ("dynamic".equalsIgnoreCase(l.getposition())) { %>
<div id="dynamic" style="display: block">  
<% } else { %>
<div id="dynamic" style="display: none">  
<% }  %>
<div class="row title">
Latitude ID (optional):</div>
<input class="inputfield" type="input" name="latitudeId" />
</div>

<% if ("static".equalsIgnoreCase(l.getposition())) { %>
<div id="static" style="display: block">  
<% } else { %>
<div id="static" style="display: none">  
<% }  %>
<div class="sub black">Set Static Position:</div> 
<div class="mapWrapper" style="width: 100%; padding: 10px;">
<div style="height: 400px; width: 100%; clear:left; float: left" id="map_canvas"></div>
</div>
<div class="row" style="min-width: 250px">Dept Latitude:</div>
<div id="latitude" class="row" style="clear: none; width: 40%; overflow: hidden"></div>
<div class="row" style="min-width: 250px">Dept Longitude:</div>
<div id="longitude" class="row" style="clear: none; width: 40%; overflow: hidden"></div>
</div>

<div class="row">VRU:</div>
<div class="row">
  <input type="radio" name="vru" value="0" style="margin-right: 5px"
    <% if ("0".equalsIgnoreCase(l.getvru())) { out.print("checked=\"checked\""); }  %>/>None
  <input type="radio" name="vru" value="1" style="margin: 0px 5px 0px 12px"
    <% if ("1".equalsIgnoreCase(l.getvru())) { out.print("checked=\"checked\""); } %>/>VRU1
  <input type="radio" name="vru" value="2" style="margin: 0px 5px 0px 12px"
    <% if ("2".equalsIgnoreCase(l.getvru())) { out.print("checked=\"checked\""); } %>/>VRU2
  <input type="radio" name="vru" value="3" style="margin: 0px 5px 0px 12px"
    <% if ("3".equalsIgnoreCase(l.getvru())) { out.print("checked=\"checked\""); } %>/>VRU3
</div>
<div class="row">Special?:</div>
<div class="row">
  <input type="radio" name="special" value="yes" style="margin-right: 5px"
  <% if ("yes".equalsIgnoreCase(l.getspecial())) { out.print("checked=\"checked\""); }%>/>Yes 
  <input type="radio" name="special" value="no" style="margin: 0px 5px 0px 12px"
  <% if ("no".equalsIgnoreCase(l.getspecial())) { out.print("checked=\"checked\""); }%>/>No
</div>
      
<div class="sub black">Associated Statuses</div>

 <%
 // determine if each Status checkbox should be checked for this Location
 String tempStatus = "init";
 for (Status deptAllowableStatus : allStatuses) {
   
   if (!tempStatus.equalsIgnoreCase(deptAllowableStatus.gettype())) { %> 
   <div class="sub white"><%=deptAllowableStatus.gettype()%></div>
   <% } %>
   
   <label for="<%=deptAllowableStatus.getshortName()%>|stat">
   <div class="row"><%=deptAllowableStatus.getshortName() %> 
   <% String checkboxOn = "";
   for (Long selectedStatus : selectedStatuses) {
     if (deptAllowableStatus.getid().equals(selectedStatus)) {
        System.out.println("passed selected test");
        checkboxOn = " checked ";
     }
   }
   %>
   <input id="<%=deptAllowableStatus.getshortName()%>|stat" 
          style="float: right; margin: 5px 10px" type="checkbox" 
          name="statusId" value="<%=deptAllowableStatus.getid() %>" <%=checkboxOn %> />
   </div>   
   </label>
   <%
     if (!deptAllowableStatus.gettype().isEmpty()) {
          tempStatus = deptAllowableStatus.gettype().toString(); 
     }
 }
 %>

</form>

<!--BUTTONS-->
<div id="centeredButtons"><ul><li>
<a class="button blue narrow tall first last"  style="margin-top: 40px"
   href="location?action=display&locationId=<%=l.getid() %>&deptId=<%=l.getdeptId() %>">
   Cancel</a></li><li>
<a class="button green narrow tall first last" style="margin-top: 40px"
   href="#" onclick="javascript:document.forms[0].submit();return false;">
   Save</a></li></ul></div>
   
<div class="hints">Quick Hints:</div>
<div class="reportWrapper">
Position: This field refers to whether or not this Location is geographically fixed.  For instance,
a firehouse, hospital or draft site would have fixed gps coordinates where a vehicle would not.
</div>
  
<!--FOOTER-->
<div class="footer">FirstResponder</div>

<!--OUTLINE WRAPPER -->
</div> 

</body>
</html>
